/*
 * util.cpp
 *
 *  Created on: 2013-10-31
 *      Author: pan.jinghua
 */

#include <windows.h>
#include <stdio.h>

#include "util.h"

const char* conv(const char* str, UINT from, UINT to) {
    int len = MultiByteToWideChar(from, 0, str, -1, NULL, 0);
    wchar_t* wstr = new wchar_t[len + 1];
    memset(wstr, 0, len * 2 + 2);
    MultiByteToWideChar(from, 0, str, -1, wstr, len);
    len = WideCharToMultiByte(to, 0, wstr, -1, NULL, 0, NULL, NULL);
    char* rstr = new char[len + 1];
    memset(rstr, 0, len + 1);
    WideCharToMultiByte (to, 0, wstr, -1, rstr, len, NULL,NULL);
    free(wstr);
    return rstr;
}

const wchar_t* convw(const char* str, UINT from) {
    int len = MultiByteToWideChar(from, 0, str, -1, NULL, 0);
    wchar_t* wstr = new wchar_t[len + 1];
    memset(wstr, 0, len * 2 + 2);
    MultiByteToWideChar(from, 0, str, -1, wstr, len);
    return wstr;
}




